<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page import="java.text.*" %>
<%@ page import="com.bmp.dao.impl.ProjectDaoImpl" %>
<%@ page import="com.bmp.dao.ProjectDao" %>
<%@ page import="com.bmp.model.Project" %>
<%@ page import="com.bmp.dao.impl.UserDaoImpl" %>
<%@ page import="com.bmp.dao.UserDao" %>
<%@ page import="com.bmp.model.User" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>casesInfo.jsp</title>
	<base href="<%=basePath%>">
	<link rel="stylesheet" type="text/css" href="js/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="js/themes/icon.css">
	<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="js/jquery.easyui.min-1.2.0.js"></script>
	<script type="text/javascript" src="js/easyDemo.js"></script>
	<script>
		$(function(){
			$('#test').datagrid({
				title:'测试用例管理',
				iconCls:'icon-edit',
				width: 700,  
		        height: 'auto',  
		        nowrap: false,  
		        striped: true,  
		        border: true,  
		        collapsible:false,//是否可折叠的  
		        fit: true,//自动大小 
		        remoteSort:false, 
		        //AllowPaging:true,  
		        //OnPageIndexChanged:ChangePage,
		        idField:'fldId',  
		        singleSelect:false,//是否单选  
		        pagination:true,//分页控件  
		        rownumbers:true,//行号  
				url:'casesInfo.action',//数据源
				loadMsg:'数据装载中......',
				frozenColumns:[[
	                {field:'ck',checkbox:true}
	               // ,{title:'code',field:'code',width:30,sortable:true}
				]],
				columns:[[
			         {title:'ID',field:'id',width:'30',rowspan:2,align:'center'},
     				 {title:'用例名',field:'name',width:'80',rowspan:2,align:'center'},
     				 {title:'所属项目',field:'p_name',width:'80',rowspan:2,align:'center'},
     				 {title:'测试步骤',field:'proce',width:'150',rowspan:2,align:'left'},
     				 {title:'预期结果',field:'expect',width:'60',rowspan:2,align:'center'},    				 
     				 {title:'创建人',field:'builder',width:'60',rowspan:2,align:'center'},
     				 {title:'创建时间',field:'build_date',width:'60',rowspan:2,align:'center'},
     				 {title:'状态',field:'status',width:'60',rowspan:2,align:'center'},
     				 {title:'测试结果',field:'actual',width:'60',rowspan:2,align:'center'},
     				 {title:'测试人',field:'appointer',width:'60',rowspan:2,align:'center'},
     				 {title:'测试时间',field:'test_date',width:'60',rowspan:2,align:'center'},
     				 {field:'opt',title:'操作',width:80,align:'center', rowspan:2,  
                         formatter:function(value,rec){  
                         //alert(rec.id);       
                         return '<span style="color:red" mce_style="color:red"><a href="javascript:audit('+rec.id+',1)" mce_href="javascript:audit('+rec.id+',1)">修改</a> <a href="javascript:audit('+rec.id+',2)" mce_href="javascript:audit('+rec.id+',2)">删除</a></span>';  
                               
                         }  
                     }
				]],
				toolbar:[{
					id:'btnadd',
					text:'Add',
					iconCls:'icon-add',
					handler:function(){
						$('#btnsave').linkbutton('enable');
						//alert('add')
					}
				},{
					id:'btncut',
					text:'Cut',
					iconCls:'icon-cut',
					handler:function(){
						$('#btnsave').linkbutton('enable');
						alert('cut')
					}
				},'-',{
					id:'btnsave',
					text:'Save',
					disabled:true,
					iconCls:'icon-save',
					handler:function(){
						$('#btnsave').linkbutton('disable');
						alert('save')
					}
				}]
			});
			var p = $('#test').datagrid('getPager');  
		    $(p).pagination({  
		        pageSize: 10,//每页显示的记录条数，默认为10  
		        pageList: [5,10,15],//可以设置每页记录条数的列表  
		        beforePageText: '第',//页数文本框前显示的汉字  
		        afterPageText: '页    共 {pages} 页',  
		        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',  
		        /*onBeforeRefresh:function(){ 
		            $(this).pagination('loading'); 
		            alert('before refresh'); 
		            $(this).pagination('loaded'); 
		        }*/
		    });			
		});
		function resize(){
			$('#test').datagrid('resize', {
				width:700,
				height:400
			});
		}
		function getSelected(){
			var selected = $('#test').datagrid('getSelected');
			if (selected){
				alert(selected.code+":"+selected.name+":"+selected.addr+":"+selected.col4);
			}
		}
		function getSelections(){
			var ids = [];
			var rows = $('#test').datagrid('getSelections');
			for(var i=0;i<rows.length;i++){
				ids.push(rows[i].code);
			}
			alert(ids.join(':'));
		}
		function clearSelections(){
			$('#test').datagrid('clearSelections');
		}
		function selectRow(){
			$('#test').datagrid('selectRow',2);
		}
		function selectRecord(){
			$('#test').datagrid('selectRecord','002');
		}
		function unselectRow(){
			$('#test').datagrid('unselectRow',2);
		}
		function mergeCells(){
			$('#test').datagrid('mergeCells',{
				index:2,
				field:'addr',
				rowspan:2,
				colspan:2
			});
		} 
		//添加项目窗口
		function openPwd() {
	        $('#w').window({
	            title: '添加测试用例',
	            width: 320,
	            modal: true,
	            shadow: true,
	            closed: true,
	            height: 500,
	            resizable:false
	        });
	    }
	    //关闭添加项目窗口
	    function closePwd() {
	        $('#w').window('close');
	    }
	    $(function() {
	        openPwd();
	        $('#btnadd').click(function() {
	            $('#w').window('open');
	        });
	        $('#btnEp').click(function() {
	            serverLogin();
	        })
			$('#btnCancel').click(function(){closePwd();})		
	    });
	    function serverLogin() {
	        var $newpass = $('#txtNewPass');
	        var $rePass = $('#txtRePass');
	        $.post('/ajax/editpassword.ashx?newpass=' + $newpass.val(), function(msg) {
	            msgShow('系统提示', '恭喜，添加成功！');
	            $newpass.val('');
	            $rePass.val('');
	            close();
	        })           
	    }
	</script>
</head>
<body>
	<!-- <a href="javascript:void(0)" onclick="verify()" class="easyui-linkbutton">dataGrid</a>  -->
	 <table id="test"></table>
	 <!--<table id="test" cellspacing="0" cellpadding="0">
		<thead>  
         <tr>  
            <th field="name" width="100" align="center"><span style="font-size:13px">用例名</span></th>
            <th field="pro_id" width="100"align="center"><span style="font-size:13px">所属项目</span></th>   
            <th field="proce" width="120"align="left"><span style="font-size:13px">测试步骤</span></th>  
            <th field="expect" width="60" align="center"><span style="font-size:13px">预期结果</span></th>  
            <th field="actual" width="60" align="center"><span style="font-size:13px">测试结果</span></th> 
            <th field="builder_id" width="60" align="center"><span style="font-size:13px">创建人</span></th>
            <th field="appoint_id" width="60" align="center"><span style="font-size:13px">测试人</span></th>
            <th field="build_date" width="60" align="center"><span style="font-size:13px">创建时间</span></th>
            <th field="test_date" width="60" align="center"><span style="font-size:13px">测试时间</span></th>
            <th field="status" width="60" align="center"><span style="font-size:13px">状态</span></th>
           </tr>
         </thead>
	</table>-->
	
	<div id="w" class="easyui-window" title="添加测试用例" collapsible="false"
			minimizable="false" maximizable="false" icon="icon-save"
			style="width: 320px; height: 500px; padding: 5px; background: #fafafa;">
			<div class="easyui-layout" fit="true">
				<div region="center" border="false" 
					style="padding: 10px; background: #fff; border: 1px solid #ccc;">
					<table cellpadding="4" style="font-size: 14px;color: #3A5FCD">
						<tr>
							<td>
								用例名：
							</td>
							<td>
								<input id="name" style="width:150px;height:25px" type="text" value=""
									class="easyui-validatebox" required="true" 
									validtype="length[3,15]" >
							</td>
						</tr>
						<tr>
							<td>
								所属项目：
							</td>
							<td>
								<select id="project" class="easyui-combobox" style="width:150px;height:25px" required="true" panelHeight="100px" name="role">
									<%
										ProjectDao pd= new ProjectDaoImpl();
										List<Project> projects = pd.getAllProjects();
										UserDao ud= new UserDaoImpl();
										List<User> users = ud.getAllUsers();
										for(int i=0;i<projects.size();i++){   
										Project project = projects.get(i);
	                                %>
									<option value="<%=project.getId() %>"><%=project.getP_name() %></option>
									<%} %>
								</select>
							</td>
						</tr>
						<tr>
							<td>
								测试步骤：
							</td>
							<td>
								<textarea cols="proce" rows="4" style="width:150px;" id="proce" type="text" class="easyui-validatebox"
									value="" required="true" validtype="length[3,10]" ></textarea>			
							</td>
						</tr>	
						<tr>
							<td>
								预期结果：
							</td>
							<td>
								<input id="except" style="width:150px;height:25px" type="text" class="easyui-validatebox"
									value="" required="true" validtype="length[3,10]" />
							</td>
						</tr>
						<tr>
							<td>
								测试结果：
							</td>
							<td>
								<input id="actual" style="width:150px;height:25px" type="text"
									value="" required="true"/>					
							</td>
						</tr>
						<tr>
							<td>
								创建人：
							</td>
							<td>
								<select id="creater" class="easyui-combobox" style="width:150px;height:25px" required="true" panelHeight="100px" name="creater">
									<%	
										for(int i=0;i<users.size();i++){   
										User user = users.get(i);
	                                %>
									<option value="<%=user.getId() %>"><%=user.getName() %></option>
									<%} %>
								</select>
							</td>
						</tr>
						<tr>
							<td>
								测试人：
							</td>
							<td>
								<select id="tester" class="easyui-combobox" style="width:150px;height:25px" required="true" panelHeight="100px" name="creater">
									<%	
										for(int i=0;i<users.size();i++){   
										User user = users.get(i);
	                                %>
									<option value="<%=user.getId() %>"><%=user.getName() %></option>
									<%} %>
								</select>
							</td>
						</tr>
						<tr>
							<td>
								创建时间：
							</td>
							<td>
								<input id="create_date" style="width:150px;height:25px" type="text" class="easyui-validatebox"
									value="<%=new SimpleDateFormat("yyyy-MM-dd").format(new Date())%>" required="true" validtype="length[3,10]" />								
							</td>
						</tr>
						<tr>
							<td>
								测试时间：
							</td>
							<td>
								<input id="test_date" style="width:150px;height:25px" type="text" 
									value="" required="true"/>				
							</td>
						</tr>
						<tr>
							<td>
								状态：
							</td>
							<td>
								<select id="creater" class="easyui-combobox" style="width:150px;height:25px" required="true" panelHeight="auto" name="creater">
									<option value="正常">正常</option>
									<option value="异常">异常</option>
								</select>
							</td>
						</tr>
					</table>
				</div>
				<div region="south" border="false"
					style="text-align: center; height: 30px; line-height: 30px;">
					<a id="btnEp" class="easyui-linkbutton" icon="icon-ok"
						href="javascript:void(0)">添加</a>
					<a id="btnCancel" class="easyui-linkbutton" icon="icon-cancel"
						href="javascript:void(0)"> 取消</a>
				</div>
			</div>
		</div>
</body>
</html>